home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 May / CMCD0504.ISO / Software / Freeware / Programare / gdiplusdelphi / demos / Using a Brush to Fill Shapes / Filling a Shape with an Image Texture / GDITEST22.dpr
Encoding:
Text File  |  2003-10-15  |  2.5 KB  |  97 lines

  1. program GDITEST22;
  2.  
  3. uses
  4.   Windows,
  5.   Messages,
  6.   SysUtils,
  7.   GDIPAPI,
  8.   GDIPOBJ;
  9.  
  10.  
  11. Procedure OnPaint(DC: HDC);
  12. var
  13.   graphics : TGPGraphics;
  14.   Image: TGPImage;
  15.   tBrush: TGPTextureBrush;
  16.   Matrix: TGPMatrix;
  17. begin
  18.   graphics := TGPGraphics.Create(DC);
  19.   Image := TGPImage.Create('..\..\Media\Texture1.jpg');
  20.   tBrush := TGPTextureBrush.Create(image);
  21.   Matrix := TGPMatrix.Create(75.0/640.0, 0.0, 0.0, 75.0/480.0, 0.0, 0.0);
  22.   tBrush.SetTransform(Matrix);
  23.   graphics.FillEllipse(tBrush, MakeRect(0, 150, 150, 250));
  24.  
  25.   Image.Free;
  26.   tBrush.Free;
  27.   Matrix.Free;
  28.   graphics.Free;
  29. end;
  30.  
  31.  
  32. function WndProc(Wnd : HWND; message : UINT; wParam : Integer; lParam: Integer) : Integer; stdcall;
  33. var
  34.   Handle: HDC;
  35.   ps: PAINTSTRUCT;
  36. begin
  37.   case message of
  38.     WM_PAINT:
  39.       begin
  40.         Handle := BeginPaint(Wnd, ps);
  41.         OnPaint(Handle);
  42.         EndPaint(Wnd, ps);
  43.         result := 0;
  44.       end;
  45.  
  46.     WM_DESTROY:
  47.       begin
  48.         PostQuitMessage(0);
  49.         result := 0;
  50.       end;
  51.  
  52.    else
  53.       result := DefWindowProc(Wnd, message, wParam, lParam);
  54.    end;
  55. end;
  56.  
  57. var
  58.   hWnd     : THandle;
  59.   Msg      : TMsg;
  60.   wndClass : TWndClass;
  61. begin
  62.    wndClass.style          := CS_HREDRAW or CS_VREDRAW;
  63.    wndClass.lpfnWndProc    := @WndProc;
  64.    wndClass.cbClsExtra     := 0;
  65.    wndClass.cbWndExtra     := 0;
  66.    wndClass.hInstance      := hInstance;
  67.    wndClass.hIcon          := LoadIcon(0, IDI_APPLICATION);
  68.    wndClass.hCursor        := LoadCursor(0, IDC_ARROW);
  69.    wndClass.hbrBackground  := HBRUSH(GetStockObject(WHITE_BRUSH));
  70.    wndClass.lpszMenuName   := nil;
  71.    wndClass.lpszClassName  := 'GettingStarted';
  72.  
  73.    RegisterClass(wndClass);
  74.  
  75.    hWnd := CreateWindow(
  76.       'GettingStarted',       // window class name
  77.       'Filling a Shape with an Image Texture',       // window caption
  78.       WS_OVERLAPPEDWINDOW,    // window style
  79.       Integer(CW_USEDEFAULT), // initial x position
  80.       Integer(CW_USEDEFAULT), // initial y position
  81.       Integer(CW_USEDEFAULT), // initial x size
  82.       Integer(CW_USEDEFAULT), // initial y size
  83.       0,                      // parent window handle
  84.       0,                      // window menu handle
  85.       hInstance,              // program instance handle
  86.       nil);                   // creation parameters
  87.  
  88.    ShowWindow(hWnd, SW_SHOW);
  89.    UpdateWindow(hWnd);
  90.  
  91.    while(GetMessage(msg, 0, 0, 0)) do
  92.    begin
  93.       TranslateMessage(msg);
  94.       DispatchMessage(msg);
  95.    end;
  96. end.
  97.